﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using dhDataAcess.dataAcess;

namespace dhDataAcess.produceDAL
{
   public  class pdckMasterDAL
    {
       //string tableName = "pdckMaster";
        private SqlTransaction tran = null;
        private SqlConnection conn = null;
        public pdckMasterDAL(SqlTransaction _transaction, SqlConnection _conn)
        {
            tran = _transaction ;
            conn = _conn;
        }
        /// <summary>
        /// 插入胚带出库主表数据
        /// </summary>
        /// <param name="deptRow"></param>
        /// <returns></returns>
        public int pdckMasterInsertII(purchase.pdckMasterDataTable masterTable, purchase.pdckDetailDataTable detailTable)
        {
            DataTable dt = new DataTable();

            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.StoredProcedure;
            string insertstr = "pdckUpdate";
            SqlParameter par = new SqlParameter("@pdckMaster", masterTable);
            par.SqlDbType = SqlDbType.Structured;
            par.TypeName = "pdckMasterTableType";
            cmd.Parameters.Add(par);


            SqlParameter par1 = new SqlParameter("@pdckDetail", detailTable);
            par1.SqlDbType = SqlDbType.Structured;
            par1.TypeName = "pdckDetailTableType";
            cmd.Parameters.Add(par1);

            cmd.CommandText = insertstr;
            cmd.Transaction = tran;
            int i = cmd.ExecuteNonQuery();
            return i;
        }
        /// <summary>
        /// 删除一行胚带出库主表更新库存数据
        /// </summary>
        /// <param name="deptRow"></param>
        /// <returns></returns>
        public int pdckDel(string billNo)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.StoredProcedure;
            SqlParameter[] para = {
                                     
                                        new SqlParameter ("@billNo",billNo )
                                   };
            cmd.Parameters.AddRange(para);
            cmd.CommandText = "pdckDel";
            cmd.Transaction = tran;
            int i = cmd.ExecuteNonQuery();
            return i;
        }
        /// <summary>
        /// 删除一行胚带入库主表更新库存数据
        /// </summary>
        /// <param name="deptRow"></param>
        /// <returns></returns>
        public int pdckDelII(string billNo)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.StoredProcedure;
            SqlParameter[] para = {
                                     
                                        new SqlParameter ("@billNo",billNo )
                                   };
            cmd.Parameters.AddRange(para);
            cmd.CommandText = "pdckdel";
            cmd.Transaction = tran;
            int i = cmd.ExecuteNonQuery();
            return i;
        }
    }
}
